10. Intent Verification Code Example

Intent Verification Code Example

Now let's see Intent Verification in practice. Navigate again to the IntentBasicSample code created by the Google team.

(See the previous concept for an explanation of the DialerActivity and the @Rule and @Before components of DialerActivityTest.)

DialerActivity screen

DialerActivity screen

@Test - typeNumber_ValidInput_InitiatesCall()

This test mocks typing a phone number into the EditText field in the DialerActivity and verifies that the intent to the dialer was sent with the correct action, phone number, and package.

This part of the code simulates typing the phone number into the DialerActivity:

This portion of the method verifies the intent to the dialer has the correct action, data, and package:

Summary

The Intent Verification test, typeNumber_ValidInput_InitiatesCall(), verifies the intent that is sent contains the correct information (e.g. action, data, package).